package Client.Manager
{
	import Client.VO.CommandVO;
	
	/**
	 * class		AreaMgr
	 * @desc		used to manage the commands
	 * @author		Aqua
	 * @date		2011-9-8
	 */
	public class CommandMgr
	{
		//---------------------//
		//      Singleton      //
		//---------------------//
		
		/**************************************************************************
		 * function					instance getter
		 * @desc					a private function used to enforce singlton
		 * @return	CommandMgr		singleton instance of this class
		 *************************************************************************/
		public static function get instance():CommandMgr
		{
			if(null == _instance)
			{
				_instance = new CommandMgr(singleton);
			}
		
			return _instance;
		}
		
		/**************************************************************************
		 * function			singleton
		 * @desc			a private function used to enforce singlton
		 *************************************************************************/
		private static function singleton():void
		{
			
		}
		
		
		//---------------------//
		//     Constructor     //
		//---------------------//
		
		/**************************************************************************
		 * function			CommandMgr
		 * @desc			constructor of class
		 * @param	s		a private function used to enforce singlton
		 *************************************************************************/
		public function CommandMgr(s:Function = null):void
		{
			if (singleton != s)
			{
				throw new Error("This is a singleton class!");
			}
		}
		
		
		//-----------------//
		//     Publics     //
		//-----------------//
		
		/**************************************************************************
		 * function			initialize
		 * @desc			initialize the manager, mainly load command data
		 *************************************************************************/
		public function initialize():void
		{
			var xml			:XML;
			var dataXML		:XML;
			var typeList	:Array;
			var index		:String;
			var type		:String;
			
			xml			= ResourceMgr.instance.getResource(ResourceMgr.XML_COMMAND) as XML;
			typeList	= [MARCH, DEFENSE, SUPPORT, RAID, CONSOLIDATE];
			
			for (index in typeList)
			{
				type	= typeList[index];
				dataXML	= xml[type];
				
				_commandList[type]	= {
					nameEn	:dataXML.name_en,
					nameCh	:dataXML.name_ch,
					command	:[]
				}
				
				initCommandList(type, _commandList[type].command, xml[type].command);
			}
			
			function initCommandList(type:String, commandList:Array, dataList:XMLList):void
			{
				var item	:XML;
				var vo		:CommandVO;
				
				for each(item in dataList)
				{
					vo			= new CommandVO();
					vo.type		= type;
					vo.value	= int(item.value);
					vo.star		= (1 == item.star);
					vo.used		= false;
					
					commandList.push(vo);
				}
			}
		}
				
		
		//------------------//
		//     Privates     //
		//------------------//
		
		
		public static const MARCH		:String = "march";
		public static const DEFENSE		:String = "defense";
		public static const SUPPORT		:String = "support";
		public static const RAID		:String = "raid";
		public static const CONSOLIDATE	:String = "consolidate";
		
		
		private static var _instance:CommandMgr;
		
		private var _commandList	:Object;
	}
	
}